import API from '@/common/api.js';
import CONFIG from '@/common/config.js'
export default {
	data() {
		return {
			PagIng: {
				page: 1,
				pageNum: 10
			},
			needLoginArr: [
				'user/info',
				'myjifen/myjifen',
				'jifenshangcheng/jifenshangcheng',
				'order/order',
				'myyongjin/myyongjin',
				'gufen/gufen',
				'tgorder/tgorder',
				'myfensi/myfensi',
				'user/myCode',
				'quan/quan',
				'quan/yhquan',
				'address/address',
				'pingJia/pingJia',
				'yjFanKui/yjFanKui',
				'order/qrOrder',
			]
		};
	},
	computed: {
		setkm() {
			return (data) => {
				let num = parseInt(data) / 1000;
				return `${num.toFixed(2)}km`
			};
		},
		setTxt() {
			return (data) => {
				if (data instanceof Array) {
					if (data.length > 0) {
						return data.map((item) => item.title).join(',');
					} else {
						return '';
					}
				}
			};
		},
		phone_mask() {
			let empty = ''
			return (data) => {
				if (data) {
					return `${data.substring(0, 3)}****${data.substring(7)}`
				} else {
					return `${empty.substring(0, 3)}****${empty.substring(7)}`
				}
			};
		},
		pimg() {
			return (data) => {
				return `${CONFIG.tp}${data}`
			};
		}
	},
	watch: {},
	filters: {},
	created() {},
	methods: {
		GoKeFu(mobile) {
			uni.makePhoneCall({
				phoneNumber: mobile
			});
		},
		wh_modal(content = '维护中') {
			uni.showModal({
				title: '提示',
				content,
				showCancel: false
			})
		},
		j_modal(content = '', fun, qxfun) {
			uni.showModal({
				title: '提示',
				content,
				confirmColor: '#e54e4f',
				showCancel: !!qxfun,
				success: (res) => {
					if (res.confirm) fun()
				}
			});
		},
		restList() {
			this.paging.page = 1;
			this.list = [];
		},
		j_copy(data) {
			uni.setClipboardData({
				data,
				success: (res) => {
					console.log('复制-res', res);
				}
			});
		},
		toNav(route) {
			let localStorage = uni.getStorageSync('localStorage');
			if (!localStorage.username) {
				if (this.needLoginArr.includes(route.split('?')[0])) {
					uni.showModal({
						title: '提示',
						content: `您还没有登陆，要去登录吗？`,
						cancelText: "取消", // 取消按钮的文字  
						confirmText: "确认", // 确认按钮的文字  
						showCancel: true, // 是否显示取消按钮，默认为 true
						success: (res) => {
							if (res.confirm) {
								uni.navigateTo({
									url: `/pages/login/login`,
								})
							}
						}
					})
					return
				}
			}
			try {
				uni.navigateTo({
					url: `/pages/${route}`,
					fail: () => {
						uni.navigateTo({
							url: `/pagesExtend/${route}`
						})
					}
				})
			} catch (e) {
				//TODO handle the exception
			}
		},
		toRed(route) {
			uni.redirectTo({
				url: `/pages/${route}`,
				fail: () => {
					uni.redirectTo({
						url: `/pagesExtend/${route}`
					})
				}
			})
		},
		toTab(route) {
			uni.switchTab({
				url: `/pages/${route}`
			})
		},
		toBack() {
			uni.navigateBack()
		},
		look(current, urls = []) {
			uni.previewImage({
				// 图片的地址
				current,
				// 图片的列表
				urls,
				// 只在app里面起作用
				loop: true,
				indicator: 'number'
			});
		},
		uuid() {
			return Math.floor(Math.random() * 100000) + Date.now()
		}
	},
};